﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.Configuration;
using System.Configuration;

namespace Subkismet.Services.GoogleSafeBrowsing.Provider
{
    public class GoogleSafeBrowsingProviderManager
    {
        private static GoogleSafeBrowsingProviderBase defaultProvider;
        private static GoogleSafeBrowsingProviderCollection providers;

        static GoogleSafeBrowsingProviderManager()
        {
            Initialize();
        }

        private static void Initialize()
        {
            try
            {
                GoogleSafeBrowsingProviderConfiguration gsbConfiguration =
                    (GoogleSafeBrowsingProviderConfiguration)
                    ConfigurationManager.GetSection("GoogleSafeBrowsingProvider");

                providers = new GoogleSafeBrowsingProviderCollection();

                ProvidersHelper.InstantiateProviders(gsbConfiguration.Providers
                    , providers, typeof(GoogleSafeBrowsingProviderBase));

                providers.SetReadOnly();

                defaultProvider = providers[gsbConfiguration.Default];
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public static GoogleSafeBrowsingProviderBase Provider
        {
            get
            {
                return defaultProvider;
            }
        }

        public static GoogleSafeBrowsingProviderCollection Providers
        {
            get
            {
                return providers;
            }
        }
    }
}
